package Factory;

import java.util.ArrayList;
import java.util.Random;

import tree.Node;
import tree.TreeNodesManager;
import tree.nodeType.Boolean.functions.BigOperator;
import tree.nodeType.Boolean.functions.EqualsOperator;
import tree.nodeType.Boolean.functions.SmallOperator;
/**
 * factory of boolean nodes with numeric sons(Big,Small,Equal)
 *
 */
public class BooleanNumericSonsFactory {
	private ArrayList<Factory>booleanFactories;
	private Random random;
	
	private class BigFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {			
			return new BigOperator(parent,depth,maxDepth,treeNodesManager);
		}
	}
	
	
	private class SmallFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {
			if (depth<maxDepth){
				return new SmallOperator(parent,depth,maxDepth,treeNodesManager);
			}
			return null;
		}
		
	}
	
	private class EqualsFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {
			return new EqualsOperator(parent,depth,maxDepth,treeNodesManager);
		}
		
	}
	
	public BooleanNumericSonsFactory() {
		booleanFactories=new ArrayList<Factory>();
		booleanFactories.add(new BigFactory());
		booleanFactories.add(new EqualsFactory());
		booleanFactories.add(new SmallFactory());
		random=new Random();
	}
	
	public Node createRandomNode(Node parent, int depth, int maxDepth,TreeNodesManager treeNodesManager){
		return booleanFactories.get(random.nextInt(booleanFactories.size()))
			.createNode(parent, depth, maxDepth,treeNodesManager);		
	}
	
	
}
